from PIL import Image

def compress_gif(input_path, output_path, palette_size=64, frame_reduction=2):
    img = Image.open(input_path)
    frames = []
    try:
        while True:
            if img.tell() % frame_reduction == 0:
                frame = img.copy()
                frame = frame.convert('P', palette=Image.ADAPTIVE, colors=palette_size)
                frames.append(frame)
            img.seek(img.tell() + 1)
    except EOFError:
        pass

    duration = img.info.get('duration', 100)
    loop = img.info.get('loop', 0)
    frames[0].save(output_path, 'GIF', save_all=True, append_images=frames[1:], duration=duration, loop=loop)

if __name__ == "__main__":
    input_path = 'input.gif'
    output_path = 'output_compressed.gif'
    compress_gif(input_path, output_path)
